project(ZLMediaTool  LANGUAGES C CXX) 
cmake_minimum_required(VERSION 3.7)

#加载自定义模块
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
#设置库文件路径
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
#设置可执行程序路径
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
#设置子目录
#set(SUB_DIR_LIST "Network" "Poller" "Thread" "Util")


add_compile_options(-std=c++11)
add_definitions(-D_CRT_SECURE_NO_WARNINGS)
add_definitions(-DNOMINMAX)


if(WIN32)
	set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
	message("Windowds  .....")
	add_definitions(-DOS_WINDOWS)
else()

	message("linux .....")

	add_definitions("-Wall -g -fPIC -O3")
if(ANDROID)
	add_definitions(-DWEBRTC_ANDROID)
	set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} -s -fPIC" )
	set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -s -fPIC" )
	set(CMAKE_C_FLAGS_RELEASE "${CMAKE_C_FLAGS_RELEASE}  -Wall -s -fPIC")
	set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} -Wall -s -fPIC")
endif()
	
endif()


#加载自定义模块

#设置子目录,共享目录
set(SRC_FILE_LIST_UTILITY "")
set(INC_FILE_LIST_UTILITY, "")

set(SUB_DIR_LIST "./src/utility")

foreach(SUB_DIR ${SUB_DIR_LIST})
    #遍历源文件
    #aux_source_directory(src/${SUB_DIR} DIR_SRCS)
	
	file(GLOB SRC_FILES "${SUB_DIR}/*.cpp" "${SUB_DIR}/*.c")
	file(GLOB INC_FILES "${SUB_DIR}/*.h")

	source_group(${SUB_DIR} FILES ${SRC_FILES} ${INC_FILES})
	
	list(APPEND SRC_FILE_LIST_UTILITY ${SRC_FILES})
	list(APPEND INC_FILE_LIST_UTILITY ${INC_FILES})
	
	include_directories(${SUB_DIR})

endforeach()


set(SRC_FILE_LIST_RTSP "")
set(INC_FILE_LIST_RTSP, "")

set(SUB_DIR_LIST "./src/rtsp")

foreach(SUB_DIR ${SUB_DIR_LIST})
    #遍历源文件
    #aux_source_directory(src/${SUB_DIR} DIR_SRCS)
	
	file(GLOB SRC_FILES "${SUB_DIR}/*.cpp" "${SUB_DIR}/*.c")
	file(GLOB INC_FILES "${SUB_DIR}/*.h")

	source_group(${SUB_DIR} FILES ${SRC_FILES} ${INC_FILES})
	
	list(APPEND SRC_FILE_LIST_RTSP ${SRC_FILES})
	list(APPEND INC_FILE_LIST_RTSP ${INC_FILES})
	
	include_directories(${SUB_DIR})

endforeach()


set(SRC_FILE_LIST_RTP "")
set(INC_FILE_LIST_RTP, "")

set(SUB_DIR_LIST "./src/librtp/include" "./src/librtp/payload" 
"./src/librtp/rtpext" "./src/librtp/source" "./src/libmpeg/include"  "./src/libmpeg/source")

foreach(SUB_DIR ${SUB_DIR_LIST})
    #遍历源文件
    #aux_source_directory(src/${SUB_DIR} DIR_SRCS)
	
	file(GLOB SRC_FILES "${SUB_DIR}/*.cpp" "${SUB_DIR}/*.c")
	file(GLOB INC_FILES "${SUB_DIR}/*.h")

	source_group(${SUB_DIR} FILES ${SRC_FILES} ${INC_FILES})
	
	list(APPEND SRC_FILE_LIST_RTP ${SRC_FILES})
	list(APPEND INC_FILE_LIST_RTP ${INC_FILES})
	
	include_directories(${SUB_DIR})

endforeach()

add_library(${CMAKE_PROJECT_NAME}_static STATIC ${INC_FILE_LIST_UTILITY} ${SRC_FILE_LIST_UTILITY})
# 链接需要用到的库文件pthread
#target_link_libraries(${CMAKE_PROJECT_NAME}_static pthread)
#target_link_libraries(${CMAKE_PROJECT_NAME}_shared avcodec avdevice avfilter avformat avutil postproc swresample swscale SDL2 )

# 修改库文件名称为myProject，系统自动改为libmyProject
set_target_properties(${CMAKE_PROJECT_NAME}_static PROPERTIES 
	OUTPUT_NAME "${CMAKE_PROJECT_NAME}")
	

add_subdirectory(example)
#
#
#set(SUB_DIR_LIST "./src/libmpeg/include"  "./src/libmpeg/source")
#
#foreach(SUB_DIR ${SUB_DIR_LIST})
#    #遍历源文件
#    #aux_source_directory(src/${SUB_DIR} DIR_SRCS)
#	
#	file(GLOB SRC_FILES "${SUB_DIR}/*.cpp" "${SUB_DIR}/*.c")
#	file(GLOB INC_FILES "${SUB_DIR}/*.h")
#
#	source_group(${SUB_DIR} FILES ${SRC_FILES} ${INC_FILES})
#	
#	list(APPEND SRC_FILE_LIST_UTILITY ${SRC_FILES})
#	list(APPEND INC_FILE_LIST_UTILITY ${INC_FILES})
#	
#	include_directories(${SUB_DIR})
#
#endforeach()

include_directories("./src/utility/")



#set(SUB_DIR "example")
##file(GLOB TEST_SRC_LIST "${SUB_DIR}/*.cpp" "${SUB_DIR}/*.c")
#aux_source_directory("example" TEST_SRC_LIST)
#
#foreach(TEST_SRC ${TEST_SRC_LIST})
#
#	STRING(REGEX REPLACE "^${SUB_DIR}/|\\.c[a-zA-Z0-9_]*$" "" TEST_EXE_NAME ${TEST_SRC})
#
#    message(STATUS "添加测试程序:${TEST_EXE_NAME}")
#    add_executable(${TEST_EXE_NAME} ${TEST_SRC} ${SRC_FILE_LIST_UTILITY} ${INC_FILE_LIST_UTILITY})
#    #target_link_libraries(${TEST_EXE_NAME} zlrtsp)
#endforeach(TEST_SRC ${TEST_SRC_LIST})




#file(GLOB_RECURSE ALL_DIRS LIST_DIRECTORIES true "${CMAKE_CURRENT_SOURCE_DIR}/example/*")


#file(GLOB_RECURSE ALL_DIRS LIST_DIRECTORIES true "./example/*")
#foreach(SUB_DIR ${ALL_DIRS})
#    if(IS_DIRECTORY ${SUB_DIR})
#        message(" ${SUB_DIR}")
#		get_filename_component(LAST_FOLDER  ${SUB_DIR} NAME)
#		message(" ${LAST_FOLDER}")
#		file(GLOB SRC_FILES "${SUB_DIR}/*.cpp" "${SUB_DIR}/*.c")
#		file(GLOB INC_FILES "${SUB_DIR}/*.h")
#
#		if(${LAST_FOLDER} STREQUAL "TestRtspServer")
#			
#			source_group(${LAST_FOLDER} FILES ${SRC_FILES} ${INC_FILES})
#	
#			include_directories(${SUB_DIR})
#
#			add_executable(${LAST_FOLDER} ${SRC_FILES} ${SRC_FILE_LIST_RTSP} ${INC_FILE_LIST_RTSP} ${SRC_FILE_LIST_UTILITY} ${INC_FILE_LIST_UTILITY})
#		elseif(${LAST_FOLDER} STREQUAL "DecodePs")
#
#			source_group(${LAST_FOLDER} FILES ${SRC_FILES} ${INC_FILES})
#	
#			include_directories(${SUB_DIR})
#
#			add_executable(${LAST_FOLDER} ${SRC_FILES} ${SRC_FILE_LIST_UTILITY} ${INC_FILE_LIST_UTILITY})
#
#		else()
#
#			source_group(${LAST_FOLDER} FILES ${SRC_FILES} ${INC_FILES})
#	
#			include_directories(${SUB_DIR})
#
#			add_executable(${LAST_FOLDER} ${SRC_FILES} ${SRC_FILE_LIST_UTILITY} ${INC_FILE_LIST_UTILITY})
#
#		endif()
#
#    endif()
#endforeach()
#
#
#get_filename_component(
#    LAST_FOLDER 
#    "/path/to/your/target/folder" 
#    NAME
#)
#message("Last folder name: ${LAST_FOLDER}")


#message("New path: ${DIR}")




#foreach(SUB_DIR ${SUB_DIR_LIST})
#
#	file(GLOB SRC_FILES "${SUB_DIR}/*.cpp")
#	file(GLOB INC_FILES "${SUB_DIR}/*.h")
#
#	source_group(${SUB_DIR} FILES ${SRC_FILES} ${INC_FILES})
#	
#	
#	list(APPEND SRC_FILES ${SRC_FILE_LIST_UTILITY})
#	list(APPEND INC_FILES ${INC_FILE_LIST_UTILITY})
#	
#	STRING(REGEX REPLACE "^\\./|\\.c[a-zA-Z0-9_]*$" "" TEST_EXE_NAME ${SUB_DIR})  # 字符串处理，去掉前面路径和后缀
#    message(STATUS "添加测试程序:${TEST_EXE_NAME}")
#
#
#	#link_directories("${CMAKE_CURRENT_SOURCE_DIR}/dependencies/webrtc/lib/x64/release/")
#	#link_directories (debug "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/webrtc/lib/x64/debug/")
#	#link_directories (optimized "${CMAKE_CURRENT_SOURCE_DIR}/dependencies/webrtc/lib/x64/release/")
#
#	add_executable(${TEST_EXE_NAME} ${SRC_FILES} ${INC_FILES})
#
#	#target_link_libraries(${TEST_EXE_NAME} d3d9.lib dmoguids.lib wmcodecdspuuid.lib winmm.lib crypt32.lib iphlpapi.lib secur32.lib amstrmid.lib msdmo.lib d3d11.lib dxgi.lib ws2_32.lib)
#	#target_link_libraries(${TEST_EXE_NAME} optimized ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/webrtc/lib/x64/release/webrtc.lib)
#	#target_link_libraries(${TEST_EXE_NAME} debug ${CMAKE_CURRENT_SOURCE_DIR}/dependencies/webrtc/lib/x64/debug/webrtcd.lib)
#
#
#endforeach()

